package com.gu.controller;

import com.gu.entity.subject.TreeSubject;
import com.gu.service.EduSubjectService;
import entity.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

/**
 * Description:
 *
 * @Autor: Rolin
 * datetime: 05-20-15:49
 */
@Api(tags = "课程组件")
@RestController
@RequestMapping("/eduService/subject")
@CrossOrigin
public class EduSubjectController {

    @Resource
    private EduSubjectService eduSubjectService;

    @PostMapping("/addSubject")
    @ApiOperation("添加课程")
    public CommonResult add(MultipartFile file) {
        eduSubjectService.batchImport(file);
        return CommonResult.success();
    }

    @GetMapping("/getAllSubject")
    @ApiOperation("获取所有一二级目录")
    public CommonResult getAll() {
        List<TreeSubject> list = eduSubjectService.getAllSubject();
        return list != null ? CommonResult.success().data("list", list) : CommonResult.error();
    }

}
